package com.itheima.test11;

public class Ticket implements Runnable {
    private  int tickets = 100;
    private  Object obj = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if (tickets > 0){
                    try {
//                        obj.wait(100);
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                }else {
                    System.out.println("所有票已经售罄");
                    break;
                }
            }
            System.out.println(Thread.currentThread().getName() +
                    "还剩" + tickets + "张票");
        }
    }
}
